package com.hongye.why.util;

import android.app.Activity;
import android.content.Context;
import android.view.Gravity;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.hongye.why.R;
import com.hongye.why.base.ActivityStack;

/**
 * Toast提示工具
 */
public class ToastUtil {
    //自定义显示Toast方式

    public static void showShortToast(String msg) {
        Activity activity = ActivityStack.topActivity();
        if (activity != null) {
            Toast.makeText(activity,msg, Toast.LENGTH_SHORT).show();
        }
    }

    public static void showLongToast(String msg) {
        Activity activity = ActivityStack.topActivity();
        if (activity != null) {
            Toast.makeText(activity,msg, Toast.LENGTH_LONG).show();
        }
    }

    /**
     * 自定义Toast
     */
    private static Toast mToast;
    public static void showToast(Context context, CharSequence text, int duration) {
        if(mToast == null) {
            mToast = Toast.makeText(context, text, duration);
        } else {
            mToast.setText(text);
            mToast.setDuration(duration);
        }

        LinearLayout view = (LinearLayout) mToast.getView();
        Animation anim = AnimationUtils.loadAnimation(context, R.anim.edd_anim_toast);
        view.setAnimation(anim);
        view.setBackgroundResource(R.drawable.edd_bg_toast);
        view.setPadding(20,16,20,16);
        TextView fonts = (TextView)view.getChildAt(0);
        fonts.setTextSize(14);
        mToast.setView(view);
        mToast.setGravity(Gravity.BOTTOM , 0, 122);
        mToast.show();
    }
}
